package com.zkthink.ceres.app.product.controller;

import com.zkthink.base.R;
import com.zkthink.ceres.product.dto.IdQueryDTO;
import com.zkthink.ceres.product.dto.ProductCategoryDTO;
import com.zkthink.ceres.product.service.ProductCategoryService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Slf4j
@Validated
@AllArgsConstructor
@RestController
@RequestMapping("/productCategory")
@Api(value = "商品类目接口", tags = "商品类目接口")
public class ProductCategoryController {

    private ProductCategoryService productCategoryService;

    /** 根据层级数，查询对应的类目
     * @param depth
     * @return
     */
    @ApiOperation(value = "查询N级类目")
    @GetMapping("/findCategoryListByDepth/{depth}")
    public R<List<ProductCategoryDTO>> findCategoryListByDepth(@PathVariable Integer depth){
        return productCategoryService.findCategoryListByDepth(depth, true);
    }

    /** 根据父类目id,查询子级类目列表
     * @param dto
     * @return
     */
    @ApiOperation(value = "查询子级类目")
    @PostMapping("/queryChildCategory")
    public R<List<ProductCategoryDTO>> queryChildCategory(@RequestBody IdQueryDTO dto){
        return productCategoryService.queryChildCategory(dto, true);
    }

}
